import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入对应的路由
const discovery = () => import(/* webpackChunkName: "discovery" */ 'views/01.discovery.vue')
const playlists = () => import(/* webpackChunkName: "playlists" */ 'views/02.playlists.vue')
const songs = () => import(/* webpackChunkName: "songs" */ 'views/03.songs.vue')
const mvs = () => import(/* webpackChunkName: "mvs" */ 'views/04.mvs.vue')
const result = () => import(/* webpackChunkName: "result" */ 'views/05.result.vue')
const playlist = () => import(/* webpackChunkName: "playlist" */ 'views/06.playlist.vue')
const mv = () => import(/* webpackChunkName: "mv" */ 'views/07.mv.vue')
const dailyRecommend = () => import(/* webpackChunkName: "dailyRecommend" */ 'views/08.dailyRecommend.vue')

// 内容需要居中的页面
export const layoutCenterNames = ['discovery', 'playlists', 'songs', 'mvs', 'dailyRecommend']
export const menuRoutes = [
  {
    path: '/discovery',
    name: 'discovery',
    meta: {
      title: '发现音乐',
      icon: 'music',
    },
  },
  {
    path: '/playlists',
    name: 'playlists',
    meta: {
      title: '推荐歌单',
      icon: 'playlist-menu',
    },
  },
  {
    path: '/songs',
    name: 'songs',
    meta: {
      title: '最新音乐',
      icon: 'yinyue',
    },
  },
  {
    path: '/mvs',
    name: 'mvs',
    meta: {
      title: '最新MV',
      icon: 'mv',
    },
  },
  {
    path: '/dailyRecommend',
    name: 'dailyRecommend',
    meta: {
      title: 'Rz日推',
      icon: 'yinyue',
    },
  },
]

Vue.use(VueRouter)
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const routes = [
  { path: '/', name: 'index', redirect: '/discovery' },
  { path: '/discovery', name: 'discovery', component: discovery },
  { path: '/playlists', name: 'playlists', component: playlists },
  { path: '/songs', name: 'songs', component: songs },
  { path: '/mvs', name: 'mvs', component: mvs },
  { path: '/result/:keywords', name: 'result', component: result },
  { path: '/playlist/:id', name: 'playlist', component: playlist },
  { path: '/mv/:id', name: 'mv', component: mv },
  { path: '/dailyRecommend', name: 'dailyRecommend', component: dailyRecommend },
]

const router = new VueRouter({
  routes
})

export default router